$(document).ready(function()
{
    $("#videoTitle").focus();
    $("#videoTitle").keyup(function()
    {

        $("#video").html('');
        var search_input = $(this).val();
        var keyword = encodeURIComponent(search_input);

        var yt_url = 'http://gdata.youtube.com/feeds/api/videos?q=' + keyword + '&format=5&max-results=6&v=2&alt=jsonc';


        $.ajax({
            type: "GET",
            url: yt_url,
            dataType: "jsonp",
            success: function(response)
            {
                if (response.data.items)
                {



                    $.each(response.data.items, function(i, data)
                    {
                        var video_id = data.id;
                        var video_title = data.title;
                        var video_viewCount = data.viewCount;



                        var video_frame = "<iframe  class='restricted' src='http://www.youtube.com/embed/" + video_id + "' frameborder='0' type='text/html'></iframe>";
                        var final = "<div id='result'><div>" + video_frame + "</div><div id='title'><strong>Title : </strong>" + video_title + "</div><div id='videoId'><strong>Code : </strong><span class='label label-success'>" + video_id+ "</span></div></div>";

                        $("#video").append(final);

                    });


                }
                else
                {
                    $("#video").html("<div id='no'>No Video</div>");
                }
            }

        });







    });


});


